from datetime import datetime
import os
import random


def create_time_str():
    current_time = datetime.now()
    year = current_time.year
    month = current_time.month
    day = current_time.day
    hour = current_time.hour
    minute = current_time.minute
    second = current_time.second
    time_string = "_".join([str(year), str(month), str(day), str(hour), str(minute), str(second)])
    return time_string


# 拼接文件路径并创建目录，返回绝对路径
def create_folder(*args):
    folder = os.path.join(*args)
    if not os.path.exists(folder):
        os.makedirs(folder)
    return folder

def get_file_name(base_path,suffix):
    father, file = create_time_str()
    file = file + str(random.randint(100, 10000)) + suffix
    folder = os.path.join(base_path, father)
    if not os.path.exists(folder):
        os.makedirs(folder)
    if suffix is None or len(suffix) ==0:
        return folder
    return os.path.join(folder, file)
